package com.sec.android.app.myfiles.module.local.foldertree;

import android.content.Context;
import android.view.ContextMenu;
import android.view.MenuItem;

import com.sec.android.app.myfiles.R;
import com.sec.android.app.myfiles.feature.PrivateModeMgr;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.module.abstraction.AbsMenuImp;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.module.abstraction.FileRecord.StorageType;
import com.sec.android.app.myfiles.util.StorageMonitor;

import java.util.ArrayList;

public class FolderTreeMenuImp extends AbsMenuImp {

    public FolderTreeMenuImp(Context context, StorageType supportStorage) {
        super(context, supportStorage);
    }


    @Override
    public void createContextualMenu(ContextMenu menu, AbsMyFilesFragment fragment, FileRecord record) {
        if (record.getStorageType() == FileRecord.StorageType.FolderTree) {
            createContextualMenuOnLeftPanel(menu, record);
        }
    }

    @Override
    protected void createContextualMenuOnLeftPanel(ContextMenu menu, FileRecord record) {
        String fullPath = record.getFullPath();
        if (StorageMonitor.isRemovedExtSDCard(fullPath)) {
            return;
        }
        menu.add(0, R.id.menu_create_folder, 0, mContext.getString(R.string.menu_create_folder));
        if (!StorageMonitor.isStorageRoot(fullPath)) {
            menu.add(0, R.id.menu_delete, 0, mContext.getResources().getString(R.string.menu_delete));
            menu.add(0, R.id.menu_move, 0, mContext.getResources().getString(R.string.menu_move));
            menu.add(0, R.id.menu_copy, 0, mContext.getResources().getString(R.string.menu_copy));
            menu.add(0, R.id.menu_rename, 0, mContext.getResources().getString(R.string.menu_rename));
            menu.add(0, R.id.menu_add_shortcut, 0, mContext.getResources().getString(R.string.add_shortcut));
            PrivateModeMgr privateModeMgr = PrivateModeMgr.getInstance(mContext);
            if (privateModeMgr.isReady()) {
                if (privateModeMgr.isPrivateModePath(fullPath)) {
                    menu.add(0, R.id.menu_remove_from_private, 0, mContext.getResources().getString(R.string.remove_from_private));
                } else {
                    menu.add(0, R.id.menu_move_to_private, 0, mContext.getResources().getString(R.string.move_to_private));
                }
            }
        }
        menu.add(0, R.id.menu_details, 0, mContext.getResources().getString(R.string.menu_details));
    }

    @Override
    public boolean _onContextualItemSelected(MenuItem item, ArrayList<FileRecord> srcRecordList, FileRecord record, AbsMyFilesFragment fragment) {
        if (fragment != null) {
            srcRecordList = new ArrayList<>();
            srcRecordList.add(record);
            return super._onContextualItemSelected(item, srcRecordList, record, fragment);
        }
        return false;
    }
}
